package org.example;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:何人亮
 * Date:2024-10-18
 * 15:37
 */
public class Test {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        while(true){
            int n=sc.nextInt();//1到n个整数取三个
            int x=sc.nextInt();//总和等于x;
            if(n==0&&x==0){
                break;
            }
            System.out.println(sum(n,x));
        }
    }
    public static int sum(int n,int x) {
        int count = 0;
        for (int i = 1; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                int k = x - i - j;
                if (j < k && k <= n) {
                    count++;
                }
            }
        }
        return count;
    }
}
